using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UIElements;
public static class Logic
{

    public static void BuyItem(this object sender, ItemData data)
    {
        int total = data.cfg.Price * data.count;
        GameData.ChangeMoney(sender, -total);
        GameData.AddItem(data);
    }
    public static void SellItem(this object sender, ItemData data)
    {
        int total = data.cfg.Price * data.count;
        GameData.ChangeMoney(sender, total);
        GameData.ReduceItem(data);
    }

    public static int CalculateRate(string events)
    {
        string[] allEvent = events.Split('#');
        //默认10000，即一倍
        int Rate = 10000;
        foreach (var ev in allEvent)
        {
            if (GameData.StoryDic.ContainsKey(ev))
            {
                //rate采用叠加，即上个事件+1倍，其他-0.5，共加0.5
                Rate += (GameData.StoryDic[ev].Influence - 10000);
            }
        }
        return Rate / 10000;
    }

    public static void AddEvent(StoryInfo Event)
    {
        string eventId = Event.EventId + "";
        GameData.StoryDic[eventId] = Event;
    }
    public static void RemoveEvent(StoryInfo Event)
    {
        string eventId = Event.EventId + "";
        GameData.StoryDic.Remove(eventId);
    }

    internal static void BuyItem((UIBuyConfirmPop, ItemData ItemData) value)
    {
        throw new NotImplementedException();
    }
}

public class ItemData
{
    public Item cfg;
    public int count;
    public ItemData(Item cfg, int count)
    {
        this.cfg = cfg;
        this.count = count;
    }
}

